<?php

namespace app\api\controller\v1;


use app\api\model\Product;
use app\api\model\UserRegistered;
use app\api\model\UserTrue;
use app\common\model\Registered;
use app\common\model\UsersD;
use app\common\model\UsersF;
use app\login\model\Account;
use app\login\model\Sign;
use app\login\service\CountService;
use Driver\Cache\Redis;
use think\Db;
use think\Request;

class Test
{
    public function index()
    {
        return null;
        ini_set('max_execution_time','0');
//        $model = new Account();
//        $result = $model->everySignData();
//        return json($result);

//        $model = new \app\common\model\SignService();
//        $result = $model->everySignData(4);
//        return json($result);

//        $service = new CountService();
//        $result = $service->getSignCountData('lqb');
//        return json($result);

//        $arr = Redis::lRange(config('redis.reg'), 0, -1);
//        $arr = Redis::smembers(config('redis.record_id'), 0, -1);
//        var_dump($arr);
//        $model = new Registered();
//        $arr = $model->getSignData('lqb', 'lqb001');
//        $sign = new \app\common\controller\SignService();
//        $result = $sign->SignService('lqb001', $arr);
//
//
//        $request = app('request');
//        return json($request->header());

//        $model= new Product();
//        $ids = $model->where('status', '=', 1)
//            ->select()
//            ->column('product_id');
//        Redis::sAddArr(config('redis.ids'), $ids);
//        return json(['code'=>200, 'ids'=> $ids]);
        try{
            $model = new Registered();
            $user_model = new UserTrue();
            $all_phone = $model->where('id','>',1)->cursor();
            foreach ($all_phone as $value){
                $array = [
                    'phone' => $value['phone'],
                    'phone_md5' => md5($value['phone']),
                    'type' => 2,
                    'logo' => $value['logo'],
                    'add_time' => now_time()
                ];
                $user_model->create($array);
            }

            $modelF = new UsersF();
            $all_phone = $modelF->where('id','>',1)->cursor();
            foreach ($all_phone as $value){
                $array = [
                    'phone' => $value['phone'],
                    'phone_md5' => md5($value['phone']),
                    'type' => 1,
                    'logo' => $value['company_logo'],
                    'add_time' => now_time()
                ];
                $user_model->create($array);
            }

            $modelD = new UsersD();
            $all_phone = $modelD->where('id','>',1)->cursor();
            foreach ($all_phone as $value){
                $array = [
                    'phone' => $value['phone'],
                    'phone_md5' => md5($value['phone']),
                    'type' => 1,
                    'logo' => $value['company_logo'],
                    'add_time' => now_time()
                ];
                $user_model->create($array);
            }

            return json([
               'success' => true
            ]);
        }catch (\Exception $e){
            return json([
                'success' => false,
                'msg' => $e->getMessage()
            ]);
        }

//        $model = new Registered();
//        $user_model = new UserRegistered();
//        Db::startTrans();
//        try{
//            $model->chunk(100, function ($users) use ($user_model){
//               foreach ($users as $value){
//                   $array = [
//                       'phone' => $value['phone'],
//                       'phone_md5' => md5($value['phone']),
//                       'type' => 2,
//                       'logo' => $value['logo'],
//                       'add_time' => now_time()
//                   ];
//                   $user_model->save($array);
//               }
//            });
//
//            Db::commit();
//        }catch (\Exception $e){
//            Db::rollback();
//            return json([
//                'success' => false,
//                'msg' => $e->getMessage()
//            ]);
//        }
    }
}